﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using ncp.Business.Common;

namespace ncp.Web.handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ImageDelete : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string filename = context.Request["imgsrc"];
            if (filename==null)
            {
                return;
            }
            var userInfo = WebMasterCookie.GetCookie();
            if (userInfo != null)
            {
            string[] temp = filename.Split('/');
            string path = context.Server.MapPath("/uploadFiles/" + userInfo.UName + "/" + temp[temp.Length-1]);
            
                if (File.Exists(path))
                {
                    File.Delete(path);
                    context.Response.Write("1");
                }
                else
                context.Response.Write("0");
            }
            else
            {
                context.Response.Write("登录超时，请重新登录");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
